package com.zhangyj.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import com.zhangyj.db.DBUtil;

public class CharacterEncodingFilter implements Filter {
	private FilterConfig config = null;
	private String encode = null;

	public void init(FilterConfig arg0) throws ServletException {
		this.config = arg0;
		this.encode = config.getInitParameter("encode");

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
	 * javax.servlet.ServletResponse, javax.servlet.FilterChain)
	 */

	public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc)
			throws IOException, ServletException {
		if (this.config == null) {
			return;
		}
		req.setCharacterEncoding("utf-8");
		fc.doFilter(req, res);
		DBUtil.close();
	}

	public void destroy() {

	}

}
